package com.ssy.lingxi.transaction.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.transaction.api.dto.request.LogisticsDetailsRequest;
import com.ssy.lingxi.transaction.handler.converter.JpaJsonToLogisticsConverter;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.util.List;

/**
 * 询价单--商品
 * @author wrc
 * @date 2020/7/21
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "trade_inquiry_product")
public class InquiryProduct {

    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE,generator="inquiry_product_seq")
    @SequenceGenerator(sequenceName="trade_inquiry_product_seq", name="inquiry_product_seq",allocationSize = 1)
    private Long id;

    /**
     * 商品询价单ID
     */
    @JsonIgnore
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name="inquiryId",referencedColumnName = "id")
    private Inquiry inquiry;

    /**
     * 商品报价单ID
     */
    @JsonIgnore
    @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    @JoinColumn(name="quoteId",referencedColumnName = "id")
    private Quote quote;

    /**
     *商品ID
     */
    private Long commodityId;

    /**
     *商品skuId
     */
    @Column(name  = "product_id")
    private Long productId;

    /**
     *商品名称
     */
    @Column(name  = "product_name")
    private String productName;

    /**
     *品类
     */
    private String category;

    /**
     *商品品牌
     */
    private String brand;

    /**
     *单位
     */
    private String unit;

    /**
     *采购数量
     */
    private Double purchaseCount;

//    /**
//     *商品询价单ID
//     */
//    private Long  inquiryListId;

//    /**
//     *询价报价单ID
//     */
//    private Long  productQuotationId;

    /**
     *总金额
     */
    private Double  money;

    /**
     *报价单价
     */
    private Double price;

    /**
     *供应会员ID
     */
    private Long  memberId;

    /**
     *供应会员ID
     */
    private Long  memberRoleId;

    /**
     * 物流信息
     */
    @Convert(converter = JpaJsonToLogisticsConverter.class)
    @Column(columnDefinition="jsonb")
    private LogisticsDetailsRequest logistics;

    /**
     * 最小起订数
     */
    @Column
    private Double minOrder;

    /**
     * 税率
     */
    @Column(columnDefinition = "decimal")
    private Double taxRate = 0d;

    /**
     *商品主图
     */
    @Column
    private String  imgUrl;

    /**
     * 是否不限制区域
     */
    @Column(columnDefinition = "boolean")
    private Boolean isAllArea = true;

    /**
     * 归属地市
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "inquiryProduct", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    private List<CommodityArea> commodityAreaList;

    /**
     * 上游商品skuId
     */
    @Column(columnDefinition = "int8")
    private Long upperCommoditySkuId;

    /**
     * 上游供应会员id
     */
    @Column(columnDefinition = "int8")
    private Long upperMemberId;

    /**
     * 上游供应会员名称
     */
    @Column(columnDefinition = "varchar(20)")
    private String upperMemberName;

    /**
     * 上游供应会员角色id
     */
    @Column(columnDefinition = "int8")
    private Long upperMemberRoleId;

    /**
     * 上游供应会员角色名称
     */
    @Column(columnDefinition = "varchar(20)")
    private String upperMemberRoleName;

    /**
     * 创建时间
     */
    private Long createTime;
}
